//bool, ObjList objs, str OUT reasonText

Hero this;
int j;

if (objs.count != 1) return false;

this = objs[0].AsHero();
if(!.IsValid()) return false;

if(.stamina < cmdcost_stamina){
	reasonText = rollover(this, "Not enough stamina");
	return false;
}
if(.army.count == 0){
	reasonText = rollover(this, "Not attached army");
	return false;
}
if(.army.count > 0){
	Unit y;
	int i, s, s_max, ps;
	for (i = 0; i<.army.count; i+=1){ 
		y = .army[i].AsUnit();
		if(y.IsValid()){
			if(y.IsHeirOf("Horse")){
				s_max += (y.maxstamina+1);
				s += (y.stamina+1);
				j+=1;
			}
		}
	}
	for (i = 0; i<.army.count; i+=1){
		y = .army[i].AsUnit();
		if(y.IsValid()){
			if(y.IsHeirOf("RangedHorse")){
				s_max += (y.maxstamina+1);
				s += (y.stamina+1);
				j+=1;
			}
		}
	}
	if(j == .army.count){
		ps = s*100/s_max;
		if(ps >= 40){
			return true;
		} else {
			reasonText = rollover(this, "Army has not enough stamina");
			return false;		
		}
	} else {
		reasonText = rollover(this, "Attach only cavalry");
		return false;		
	}
}
return true;
